package com.desehou.fristspring.controller;

import com.desehou.fristspring.model.JsonResult;
import com.desehou.fristspring.model.StatusCode;
import com.desehou.fristspring.service.GoodsService;
import com.github.pagehelper.PageHelper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class GoodsController {
    @Resource(name = "goodsServiceImpl")
    private GoodsService goodsService;

    @RequestMapping("/goods")
    public JsonResult users(Integer page, Integer page_size) {

        PageHelper.startPage(page, page_size);

        return new JsonResult(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), goodsService.goods());
    }

    @RequestMapping(value = "/goods/delete",method = RequestMethod.DELETE)
    public JsonResult deleteGoodsById(String spuSN) {

        if (goodsService.deleteGoodsById(spuSN)) {
            return new JsonResult(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(),null);
        } else {
            return new JsonResult(StatusCode.FAIL_DELETE.getCode(), StatusCode.FAIL_DELETE.getMessage(), null);
        }

    }
}
